<?php if (!defined('THINK_PATH')) exit();?><style>
	#add_Rule_form input , #modify_Rule_form input{
		width:200px;
	}
	#modify_Rule_form select,#add_Rule_form select {
		width:95px;
	}
	#add_Rule_form td ,#modify_Rule_form td{
		height: 30px;
	}
</style>
<!-- 工具栏 -->
<div id="tool-rule">    
<table>
    <tr>
        <td>
            <a href="#" id="aaa1" class="easyui-linkbutton" onclick='show_add_mRule()' data-options="iconCls:'icon-standard-folder-add',plain:true">新建主权限</a>
            <a href="#" id="aaa1" class="easyui-linkbutton" onclick='show_add_sRule()' data-options="iconCls:'icon-standard-folder-page',plain:true">新建子权限</a>
            <a href="#" id="aaa1" class="easyui-linkbutton" onclick='del_Rule()' data-options="iconCls:'icon-standard-page-white-delete',plain:true">删除</a>
            <a href="#" id="aaa1" class="easyui-linkbutton" onclick='show_modify_Rule()' data-options="iconCls:'icon-standard-application-edit',plain:true">修改</a>
        </td>
    </tr>
</table>
</div>
<!-- 工具栏end -->
<!-- 新建菜单对话框 -->
<div id="add_Rule_dialog" class="easyui-dialog" style="width:360px; height: 195px; padding: 10px 50px; overflow: hidden;" title="新建权限" data-options="iconCls:'icon-standard-folder-page',buttons:'#add_Rule_tool',closed:true,resizable:true,modal:true,closable:true">
	<form id="add_Rule_form" method="post">
	<input type="hidden" id="pid" name="pid"/>
	    	<table cellpadding="5">
	    		<tr>
	    			<td>标题:</td>
	    			<td><input class="easyui-textbox" type="text" id="text" name="text" data-options="required:true,prompt:'请输入权限名称'"  ></input></td>
	    		</tr>
	    		<tr>
	    			<td>URL:</td>
	    			<td><input class="easyui-textbox" type="text" id="name" name="name" data-options="required:true,prompt:'请输入URL:如Admin/Name/add'" ></input></td>
	    		</tr>
	    		<tr>
	    			<td>类型:</td>
	    			<td>
					<select id="leixing" class="easyui-combobox" name="leixing" data-options="editable:false,panelHeight:'auto'">   
					    <option  selected="selected" value="1">菜单</option>   
					    <option value="2">操作</option>   
					    <option value="3">数据列表</option>      
					</select>
					<span id="iconFj">

						<a id="btnNewAuthIcon" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-standard-exclamation'" onclick="showSetIcon('newAuthIcon','btnNewAuthIcon')"></a>
					<input type="hidden" id='newAuthIcon' name='icon'>
					序号:
					<input class="easyui-numberbox"  id="odernumber" name="odernumber" data-options="" style="width:40px;"></input>
					</span>

					
	    			</td>
	    		</tr>		    		
	    	</table>
	    </form>

</div>
<div id="add_Rule_tool">
	<div class="tool_tip">添加后会在列表中出现！！</div>
	<a href="#" id="addok" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
		onclick="add_Rule()">确认</a>
	<a href="#" class="easyui-linkbutton"
		data-options="iconCls:'icon-cancel'"
		onclick="javascript:$('#add_Rule_dialog').dialog('close')">取消</a>
</div>
<!-- 新建菜单对话框 end-->

<!-- 修改菜单对话框 -->
<div id="modify_Rule_dialog" class="easyui-dialog" style="width:360px; height: 195px; padding: 10px 50px; overflow: hidden;" title="修改菜单" data-options="iconCls:'icon-standard-application-edit',buttons:'#modify_Rule_tool',closed:true,resizable:false,modal:true,closable:true">
	<form id="modify_Rule_form" method="post">
			<input type="hidden" id="id" name="id"/>
	    	<table cellpadding="5">
	    		<tr>
	    			<td>标题:</td>
	    			<td><input class="easyui-textbox" type="text" id="text" name="text" data-options="required:true,prompt:'请输入菜单名称'"  ></input></td>
	    		</tr>
	    		<tr>
	    			<td>URL:</td>
	    			<td><input class="easyui-textbox" type="text" id="name" name="name" data-options="required:true,prompt:'请输入URL:如Admin/Name/add'" ></input></td>
	    		</tr>
	    			<tr>
	    			<td>类型:</td>
	    			<td>
					<select id="leixingxg" class="easyui-combobox" name="leixing" data-options="editable:false,panelHeight:'auto'">   
					    <option  selected="selected" value="1">菜单</option>   
					    <option value="2">操作</option>   
					    <option value="3">数据列表</option>      
					</select>
					<span id="iconFjxg">

						<a id="btnNewAuthIconxg" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-standard-exclamation'" onclick="showSetIcon('newAuthIconxg','btnNewAuthIconxg')"></a>
					<input type="hidden" id='newAuthIconxg' name='icon'>
					序号:
					<input class="easyui-numberbox"  id="odernumberxg" name="odernumber" data-options="" style="width:40px;"></input>
					</span>
	    			</td>
	    		</tr>	
	    	</table>
	    </form>

</div>
<div id="modify_Rule_tool">
	<div class="tool_tip">添加后会在列表中出现！！</div>
	<a href="#" id="modifyok" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
		onclick="modify_Rule()">确认</a>
	<a href="#" class="easyui-linkbutton"
		data-options="iconCls:'icon-cancel'"
		onclick="javascript:$('#modify_Rule_dialog').dialog('close')">取消</a>
</div>



<!-- 修改菜单对话框 end-->

<script>
	$('#leixing').combobox({
    onChange: function(newValue,oldValue){
        // console.log(record);
        if(newValue!=1){
        	$("#iconFj").hide();
        }else{
        	$("#iconFj").show();
        }
    }
});
	$('#leixingxg').combobox({
    onChange: function(newValue,oldValue){
        // console.log(record);
        if(newValue!=1){
        	$("#iconFjxg").hide();
        }else{

        	var row = $('#rulelist').treegrid("getSelected");

        	if(row.icon!='' && row.icon){
    $('#btnNewAuthIconxg').linkbutton({    
        iconCls:row.icon
    });  
}else{
 $('#btnNewAuthIconxg').linkbutton({    
        iconCls:'icon-standard-exclamation'
    });
    
}
        	$("#iconFjxg").show();
        }
    }
});	


	// function refresh(){
	// 	    $.ajax({  
 //            type : 'POST',  
 //            dataType : "json",  
 //            url : '/degs/index.php/Admin/Public/menulist',  
 //            success : function(data) {  
 //                $.each(data, function(i, n) {
 //                	var is=$('#layout_west_accordion').accordion('select',n.text);
 //                	if(!is){
 //                		  if (i == 0) {
 //                        $('#layout_west_accordion').accordion('add', {  
 //                            title : n.text,  
 //                            iconCls : n.icon,  
 //                            selected : true,  
 //                            content : '<div style="padding:10px"><ul name="'+n.text+'"></ul></div>',  
 //                        });  
 //                    } else {  
 //                        $('#layout_west_accordion').accordion('add', {  
 //                            title : n.text,  
 //                            iconCls : n.icon,  
 //                            selected : false,  
 //                            content : '<div style="padding:10px"><ul name="'+n.text+'"></ul></div>',  
 //                        });  
 //                    }  
 //                	}
                  
  
 //                });  
 //            }  
 //        }); 

		


	// }
</script>

<div id="iconDialog" class="easyui-dialog" title="My Dialog" style="width:675px;height:399px;"   
        data-options="iconCls:'icon-standard-folder-page',buttons:'#iconDialog_tool',closed:true,resizable:true,modal:true,closable:true">   
    

    <div class="easyui-layout" data-options="fit:true">   
      <div id="content" data-options="region:'center',border:false,title:'',href:'/degs/index.php/Admin/Public/icon?page=1',loadingMessage:'正在载入图标……'" style="padding:5px;">
      </div> 
        <div data-options="region:'south',title:'',split:false,border:false" style="height:35px;" >     
            <div class="easyui-pagination" style="border:1px solid #ccc;"
                data-options="total: 1008,pageSize: 250,pageList: [10,20,50,250],onSelectPage: function(pageNumber,pageSize){$('#content').panel('refresh', '/degs/index.php/Admin/Public/icon?page='+pageNumber+'&pageSize='+pageSize);}">
            </div>
        </div>   
      
    </div>  



</div> 
<div id="iconDialog_tool">
    <div class="tool_tip" id="myIcon">请选择合适的图标</div>
    <input type="hidden" id='aIcon'/>
    <input type="hidden" id='inputIcon'/>
    <input type="hidden" id='iconVal'/>
    <a href="#" id="modifyok" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="setIcon()">确认</a>
    <a href="#" class="easyui-linkbutton"
        data-options="iconCls:'icon-cancel'"
        onclick="javascript:$('#iconDialog').dialog('close')">取消</a>
</div>


<table id="rulelist" data-options="fit:true"></table>

<script>
	$('#rulelist').treegrid({    
    url:'/degs/index.php/Admin/Rule/ruleTree',    
    idField:'id', 
    lines: true,
    rownumbers: true,   
    treeField:'text',
    nowrap : true,
    pagination : true,
    fitColumns : true,
    tool:'tool-rule',  
    autoRowHeight : true, 
    striped : true,//交替行
    singleSelect : true,//只允许选择一行
    border : false,
    columns:[[    
        {field:'id',checkbox : true},
        // {title:'id',field:'id',width:50},   
        // {field:'pid',title:'pid',width:50,align:'center'},    
       
        {field:'text',title:'标题',width:200}, 
        {field:'name',title:'URL',width:200},
        {field:'leixing',title:'类型',width:200,
        formatter: function(value,row,index){
               return ruleLx(value);
            }

    },
       {field:'icon',title:'图标',width:80,align:'center',
        formatter: function(value,row,index){
                if (value){
                  
                    return '<span class="'+value+'" style="width:150px;height:24px;display:inline-block;"></span>';
                }
            }

    } , 
     {field:'odernumber',title:'序号',width:60,align:'center',editor:{type:'numberbox',options:{precision:0}}}  
    ]],
        onDblClickCell : function(field, row) {
                         
                                     // if(field=="ordernumber"){
                                     //   $('#rulelist').treegrid('beginEdit', row.id) 
                                     // }  
                                }    
});
// 新建父菜单窗口
function show_add_mRule(){
        $('#add_Rule_form').form('load', {
            pid:0,
            text : '',
            name:''
        });
            $('#btnNewAuthIcon').linkbutton({    
    iconCls:'icon-standard-exclamation' 
}); 
        $('#add_Rule_dialog').dialog("open").dialog('setTitle', '&nbsp;&nbsp;新建主权限');
}

// 新建子权限窗口
function show_add_sRule(){
    var row = $('#rulelist').treegrid("getSelected");
    if(!row){
        $.messager.alert('新建子权限', '没有选择父节点！', 'info');
      

    }else{

   
            $('#add_Rule_form').form('load', {
            pid:row.id,
            text : '',
            name:''
        });
                       $('#btnNewAuthIcon').linkbutton({    
    iconCls:'icon-standard-exclamation' 
});     
        $('#add_Rule_dialog').dialog("open").dialog('setTitle', '&nbsp;&nbsp;新建子权限');
      
  
           
   
    }    
}

// 新建菜单
function add_Rule(){
    $('#add_Rule_form').form('submit', {

            url : '/degs/index.php/Admin/Rule/addRule',

            success : function(data) {
                $("#rulelist").treegrid("reload");

                $.messager.alert('新建权限', data, 'info');
                $('#add_Rule_dialog').dialog('close')

            }
        });
}
// 删除菜单
function del_Rule(){
      var row = $('#rulelist').treegrid("getSelected");
    if(!row){
        $.messager.alert('删除菜单', '请选择要删除的菜单！', 'info');
      

    }else{

        $.messager.confirm('确认','您确认想要删除“'+row.text+'”吗？',function(r){    
            if (r){    
                $.post('/degs/index.php/Admin/Rule/delRule', {
                            id : row.id
                        }, function(data) {
                            if (data.status==1) {
                                $.messager.alert('删除权限', data.data, 'info');
                                $("#rulelist").treegrid("reload");
                            } else {
                                $.messager.show({ // show error message  
                                    title : '错误',
                                    msg : data.data
                                });

                            }
                        }, 'json');  
            }    
        }); 
           
   
    }    
}

/**
 * 修改菜单窗口
 */
function show_modify_Rule(){
     var row = $('#rulelist').treegrid("getSelected");
    if(!row){
        $.messager.alert('修改菜单', '请选择要修改的菜单！', 'info');
    }else{
             $("#modify_Rule_form").form("load", row);
         if(row.leixing!=1){
            $("#iconFjxg").hide();
        }else{
            $("#iconFjxg").show();
if(row.icon!='' && row.icon){
    $('#btnNewAuthIconxg').linkbutton({    
        iconCls:row.icon
    });  
}else{
 $('#btnNewAuthIconxg').linkbutton({    
        iconCls:'icon-standard-exclamation'
    });
    
}

        }


   
     $("#modify_Rule_dialog").dialog("open").dialog('setTitle', '&nbsp;&nbsp;修改菜单');
           
   
    }   
}
/**
 * 修改菜单
 */
function modify_Rule(){
    
    $('#modify_Rule_form').form('submit', {
    type:'POST',
     url : '/degs/index.php/Admin/Rule/modifyRule',
    success : function(data) {
        $("#rulelist").treegrid("reload");
        $.messager.alert('修改权限', data, 'info');
        $('#modify_Rule_dialog').dialog('close')
        // 

    }
});

}
/**
 * 修改菜单
 */
function ruleLx(val){
    var lx="";
    switch(val)
    {
    case 1:
      lx="菜单";
      break;
     case 2:
      lx="操作";
      break;
    case 3:
      lx="数据";
      break;
    default:
       lx="菜单";
    }
        return lx;
}
</script>